<?php
/**
 * This file is part of xmpp.
 *
 * @auther: vlean
 */
require_once "vendor/autoload.php";

use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;

$address = "tcp://127.0.0.1:5222";
$username = "user2";
$password = "1234";



$options = new Options($address);
$options->setUsername($username)
    ->setPassword($password);


$client = new Client($options);
// optional connect manually
$client->connect();


$client->send(new Roster);
// set status to online
$pre = new Presence();
$client->send(new Presence);


// join a channel
$channel = new Presence;
$channel->setTo('lts@conference.192.168.1.5')
//    ->setPassword('channelpassword')
    ->setNickName('mynick');
$client->send($channel);

// send a message to another user
$message = new Message;
$message->setMessage('test')
    ->setTo('lts@conference.192.168.1.5')
    ->setType(Message::TYPE_GROUPCHAT);
$client->send($message);
//
//// send a message to the above channel
//$message = new Message;
//$message->setMessage('test')
//    ->setTo('channelname@conference.myjabber.com')
//    ->setType(Message::TYPE_GROUPCHAT);
//$client->send($message);

$client->disconnect();
